package cn.basic.social.api.weixintalk.request;

import cn.basic.social.api.CommonConstants;
import cn.basic.social.api.weixintalk.BaseWxRequest;
import cn.basic.social.api.exception.ApiRuleException;
import cn.basic.social.api.weixintalk.response.WxGetAccessTokenResponse;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName WxGetAccessTokenRequest
 * https://developers.weixin.qq.com/doc/oplatform/Website_App/WeChat_Login/Wechat_Login.html
 *
 * @Description 通过code获取access_token
 * @Author zlf
 * @Date 2023/9/8 14:26
 */
public class WxGetAccessTokenRequest extends BaseWxRequest<WxGetAccessTokenResponse> {

    private final String requestUrl = "https://api.weixin.qq.com/sns/oauth2/access_token";
    private String topHttpMethod = CommonConstants.HTTP_METHOD_GET;

    /**
     * 通过成员授权获取到的code，最大为512字节。每次成员授权带上的code将不一样，code只能使用一次，5分钟未被使用自动过期。
     */
    private String code;

    public WxGetAccessTokenRequest(String code) {
        this.code = code;
    }

    public WxGetAccessTokenRequest() {
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public String getLoginCode() {
        return this.code;
    }

    @Override
    public String getTopHttpMethod() {
        return this.topHttpMethod;
    }

    @Override
    public void setTopHttpMethod(String topHttpMethod) {
        this.topHttpMethod = topHttpMethod;
    }

    @Override
    public Map<String, String> getTextParams() {
        return new HashMap<>();
    }

    @Override
    public Class<WxGetAccessTokenResponse> getResponseClass() {
        return WxGetAccessTokenResponse.class;
    }

    @Override
    public void check() throws ApiRuleException {

    }

    @Override
    public String getTopContentType() {
        return null;
    }

    @Override
    public void setTopContentType(String topContentType) {

    }

    @Override
    public String getRequestUrl() {
        return this.requestUrl;
    }
}
